﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Portal.Cms.Bussiness;
using Portal.Web.Utility;
using Portal.Cms.Model;
using Portal.Utility;
using Portal.Web.Model;
using Portal.Core;
using dtSearch32Lib;
using DocumentSearchServiceModel;
using DocumentSearch32Lib;
using Portal.Systems.Model;
using Portal.Workflow.Bussiness;
using Portal.Cms.Utility;
using System.Data;

namespace Portal.Cms.Render
{
    public class SurveyResultListRenderBll
    {
        
        public static AjaxOut Draw(string SiteId)
        {
            //"     <td><input type=button class=button value=\"Xem chi tiết\" onclick=\"window.open('ViewSurveyDetail.aspx?gid=" + GroupDataId + "&StudentSurveyId=" + StudentSurveys[iIndex].StudentSurveyId + "','_self');\"></td>\r\n" +
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                string GroupDataId = (string)WebEnvironments.Request(SiteId, "gid");
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, GroupDataId);
                StudentSurveyCls[] StudentSurveys = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).ReadingVotedStudentList(SiteId, OGroupData.GroupDataId);
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string ButtonUrl = WebConfig.GetButtonIconRoot(OSiteParam);
                string Html =

                    "  <div class=DatabaseFunction>\r\n" +
                    "        <ul>\r\n" +
                    "            <li onclick=\"javascript:window.open('SurveyInputData.aspx?gid="+GroupDataId+"','_self');\"><img class=image src=\"" + ButtonUrl + "/back.png\"><div>Quay lại</div></li>\r\n" +
                    "        </ul>\r\n" +
                    "  </div>\r\n" +

                   " <input type=hidden id=txtSurveyId=\"" + OGroupData.GroupDataId + "\">\r\n" +
                   " <div class=hello>Danh sách đánh giá (" + StudentSurveys.Length.ToString("#,##0") + ")</span></div>\r\n" +
                   " <h3>" + OGroupData.GroupDataName + "</h3>\r\n";
                if (!string.IsNullOrEmpty(OGroupData.GroupDataDescription))
                {
                    Html +=
                        "    <div class=votedesc>" + OGroupData.GroupDataDescription + "</div>\r\n";
                }
                if (StudentSurveys.Length == 0)
                {
                    Html += " <div class=CssNoData>Chưa có đánh giá nào</div>\r\n";
                }
                else
                {
                    Html += "<div class=tabcontent>\r\n" +
                            "   <table>\r\n" +
                            "       <tr>\r\n" +
                            "           <th>#</th>\r\n" +
                            "           <th>Mã</th>\r\n" +
                            "           <th>Họ tên</th>\r\n" +
                            "           <th>Ngày sinh</th>\r\n" +
                            "           <th>Chuyên ngành</th>\r\n" +
                            "           <th>Khóa</th>\r\n" +
                            "           <th>Lớp</th>\r\n" +
                            "           <th>Thời gian</th>\r\n" +
                            "           <th></th>\r\n" +
                            "       </tr>\r\n";
                    for (int iIndex = 0; iIndex < StudentSurveys.Length; iIndex++)
                    {
                        string StudentId = (string)StudentSurveys[iIndex].StudentId;
                        Html += " <tr>\r\n" +
                                  "     <td>" + (iIndex + 1) + "</td>\r\n" +
                                  "     <td>" + StudentSurveys[iIndex].StudentCode + "</td>\r\n" +
                                  "     <td>" + StudentSurveys[iIndex].StudentName + "</td>\r\n" +
                                  "     <td>" + StudentSurveys[iIndex].Dob + "</td>\r\n" +
                                  "     <td>" + StudentSurveys[iIndex].TrainingSubject + "</td>\r\n" +
                                  "     <td>" + StudentSurveys[iIndex].Course + "</td>\r\n" +
                                  "     <td>" + StudentSurveys[iIndex].Class + "</td>\r\n" +
                                  "     <td>" + StudentSurveys[iIndex].SurveyDate.ToString("dd/MM/yyyy") + "</td>\r\n" +
                                  "     <td><input type=button class=button value=\"Xem chi tiết\" onclick=\"window.open('ViewSurveyDetail.aspx?gid=" + GroupDataId + "&StudentSurveyId=" + StudentSurveys[iIndex].StudentSurveyId + "','_self');\"></td>\r\n" +
                                  " </tr>\r\n";
                    }
                    Html +=
                            "</table>\r\n"+
                            "</div>\r\n";
                }
                
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            
            return OAjaxOut;
        }
    }
}
